<?php
/**
 * 文章模型
 * User 1874
 */

namespace app\adminplatform\model;
use think\facade\Request;
use think\Model;

class Article extends Model {
    /*
     * 文章列表查询
     * @param array $map 查询条件
     */
    public static function getArticleList(array $map=[]){

        return Article::where($map)->alias('a')
            ->join('admin b','a.ar_adminId=b.ad_id','left')
            ->field("ar_id,ar_title,ar_classifyId,ar_image,ar_sort,ar_subtitle,ar_status,ar_time,ad_name")
            ->order('ar_sort,ar_id DESC')->paginate(["list_rows"=>PageNum,'query'=>Request::param()]);
    }
    /*
     * 单条文章信息
     * @param array $map 查询条件
     * @param int $type 查询类型
     */
    public static function getArticleInfo(array $map=[], int $type=0){

        if($type == 0){
            return Article::where($map)->find();
        }else{
            return Article::where($map)->alias('a')
                ->join('article_classify b','a.ar_classifyId=b.ac_id','left')
                ->field('
                    ar_id,ar_title,ar_classifyId,ar_content,ar_image,ar_subtitle,ar_sort,
                    ar_time,ar_status,ac_id,ac_title
                ')->find();
        }
    }
}